<template>
  <my-table :cols="cols" :formObj="form" :rules="rules" :tableAttrs="tableAttrs"  @show-dialog="showDlg" >
    <template v-slot:form>
      <el-form-item label="学号" prop="stuNo">
        <el-input v-model="form.stuNo" placeholder="学号" clearable></el-input>
      </el-form-item>
      <el-form-item label="姓名" prop="name">
        <el-input v-model="form.name" placeholder="姓名" clearable></el-input>
      </el-form-item>
      <el-form-item label="性别" prop="sex">
        <el-input v-model="form.sex" placeholder="性别" clearable></el-input>
      </el-form-item>
    </template>
    <template v-slot:buttons>
      <el-button  type="small" icon="el-icon-button" @click="logout">注销</el-button>
    </template>
  </my-table>
</template>

<script>
  import myTable from '../../components/myTable.vue'
  export default {
    components: {
      myTable
    },
    data() {
      return {
        cols: [{
            property: 'stuNo',
            label: '学号'
          },
          {
            property: 'name',
            label: '姓名'
          },
          {
            property: 'sex',
            label: '性别'
          }
        ],
        form: {
          stuNo: '',
          name: '',
          sex: '',
        },
        //对话框
        rules: {
          stuNo: [{
            required: true,
            message: '学号必填',
            trigger: 'blur'
          }],
          name: [{
            required: true,
            message: '姓名必填',
            trigger: 'blur'
          }],
          sex: [{
            required: true,
            message: '性别必填',
            trigger: 'blur'
          }]
        },
        tableAttrs: {
          border: true
        },

      }
    },
    methods:{
      showDlg(form){

      },
      logout(){
        this.$ajax.post('logout',{}).then(res=>{
          var result=res.data;
          if(result.success){
            window.sessionStorage.removeItem("token");
            window.sessionStorage.removeItem("name");
            this.$notify.success({
              title:'提示',
              message:result.msg,
              position:'bottom-right'
            })
            this.$router.replace('/')
          }
        })
      }
    }
  }
</script>

<style>
</style>
